package com.start.platform.core.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.start.common.mybaitsplus.StartMBColumnTools;
import com.start.platform.core.entity.StartPlatformUserEntity;
import com.start.platform.core.mappers.StartPlatformUserMapper;
import com.start.platform.core.service.StartPlatformUserService;
import com.start.platform.core.vo.StartPlatformUserVo;
import org.springframework.stereotype.Service;

@Service
public class StartPlatformUserServiceImpl extends ServiceImpl<StartPlatformUserMapper, StartPlatformUserEntity> implements StartPlatformUserService {
    @Override
    public StartPlatformUserVo getUserByOpenId(String platformType, String appId, String openId) {
        QueryWrapper<StartPlatformUserVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StartMBColumnTools.getColumn(StartPlatformUserVo::getPlatformType), platformType);
        queryWrapper.eq(StartMBColumnTools.getColumn(StartPlatformUserVo::getPlatformAppId), appId);
        queryWrapper.eq(StartMBColumnTools.getColumn(StartPlatformUserVo::getPlatformOpenId), openId);
        return baseMapper.getUserByPlatform(queryWrapper);
    }

    @Override
    public StartPlatformUserEntity getByUserName(String userName) {
        QueryWrapper<StartPlatformUserVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StartMBColumnTools.getColumn(StartPlatformUserVo::getUserName), userName);
        queryWrapper.last(" limit 1");
        return baseMapper.getUserByPlatform(queryWrapper);
    }

    @Override
    public StartPlatformUserEntity getByUserPhone(String phone) {
        QueryWrapper<StartPlatformUserVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StartMBColumnTools.getColumn(StartPlatformUserVo::getPhone), phone);
        queryWrapper.last(" limit 1");
        return baseMapper.getUserByPlatform(queryWrapper);
    }
}
